﻿<!DOCTYPE html>
<meta charset="UTF-8">
<html>

<head>
    <meta charset="utf-8">
    <title>华南集团云平台</title>
    <!-- 这个必须引入的啊，钉钉的前端js SDK, 使用框架的请自行参照开发文档 -->
    <script src="https://g.alicdn.com/dingding/dingtalk-jsapi/2.7.13/dingtalk.open.js"></script>
    <!-- 这个jquery 想不想引入自己决定，没什么影响 -->
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>

<body>
    <script type="text/javascript">
        $(function () {
            //alert("0");
            //钉钉sdk 初始化
            // dd.ready参数为回调函数，在环境准备就绪时触发，jsapi的调用需要保证在该回调函数触发后调用，否则无效。
            dd.ready(function () {
                //alert("1");
                //alert(getQueryVariable("corpid"));
                //alert(getQueryVariable("gs"));
                //获取当前网页的url
                //http://ding-web.lnexin.cn/?corpid=dinga1d316c091e1ed3835c2f4657eb6378f
                var currentUrl = document.location.toString()
                $("#url").append(currentUrl)

                // 解析url中包含的corpId
                var corpId = getQueryVariable("corpid");
                //var corpId = currentUrl.split("corpid=")[1];
                ////corpId = "dinga1d316c091e1ed3835c2f4657eb6378f";
                //$("#corpId").append(corpId)

                //获取公司(对应钉钉组织的公司)
                var gs = getQueryVariable("gs");


                dd.runtime.permission.requestAuthCode({
                    corpId: corpId, //企业id
                    onSuccess: function (info) {
                        var code = info.code; //免登授权码
                        //window.location.href = "~/Login/check?phone=123123&password=admin?code=" + code;
                        window.location.href = "https://localhost:7253//api/test/getuserid?code=" + code;


                        //$.ajax({
                        //    async:false,
                        //    type:'get',
                        //    dataType:"",
                        //    data:{"code":code},
                        //    url:'/TransPortController/GetUserId',
                        //    success:function(ref){
                        //        alert(ref);
                        //    }
                        //})
                    }
                    onFail: function (err) {
                        alert('requestAuthCode fail: ' + JSON.stringify(err));
                    }
                });
            });
        })

        function getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) { return pair[1]; }
            }
            return (false);
        }    
    </script>
</body>

</html>
